/**
 * VUEshop
 * ============================================================================
 * * 版权所有 2015-2027 深圳搜豹网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.vueshop.com.cn
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: 沈小白 2020-07-22 $
 */<template> 
	<view>
		<view class="withdraw_container">
			<view class="withdraw-header-wrap">
				<view class="can_money_tit">
					<text>
						￥
					</text>
					<text>
						可提现佣金总金额
					</text>
				</view>
				<view class="can_money_con">
					<text>
						￥
					</text>
					<text>
						{{withdraw.able_withdraw_money}}
					</text>
				</view>
			</view>
			<view class="withdraw_style">
				<view class="withdraw_stna">提现方式</view>
				<block v-if="way.length>0">
					<view class="withdraw_stcon" v-for="(item,index) in way" :key="index" v-if="way.oauth==miniapp">
						<image src="/images/withdraw-weix.png" role="img"></image>
						<text class='wh_user_account' @tap='bindWechat'>{{way.openid?'已绑定'+way.oauth+'':'还未绑定'+way.oauth+''}}</text>
					</view>
				</block>
				<block v-else-if="way.length==0">
					<view class="withdraw_stcon">
						<image src="/images/withdraw-weix.png" role="img"></image>
						<text class='wh_user_account' @tap='bindWechat'>还未绑定微信</text>
					</view>
				</block>
			</view>
			<view class="withdraw-cont-wrap">
				<view class="withdraw-cont-p1">提现金额</view>
				<view class="withdraw-money">
					<text>
						￥
					</text>
					<input  v-model="params.money" id="money" name="money" type="digit"> </input>
				</view>
				<view class="withdraw-allmoney">
					<text>
						手续费:{{poundage}}
					</text>
					<button @tap="allWithdraw" class="wh_allmony" role="button" aria-disabled="false">全部提现</button>
				</view>
			</view>
			<view class="withdraw-cont-wrap">
				<view class="withdraw-cont-p2">
					<text>
						支付密码：
					</text>
					<input v-model="pay_pwd" id="paypwd" name="paypwd" placeholder="请填写支付密码" type="password">
					
					</input>
				</view>
				<view class="wh_setpsd">
					<navigator @tap.stop="userinfoEdit" :data-url="'/pages/user/userinfo_edit/userinfo_edit?type=paypwd'" role="navigation">前往设置或修改交易密码</navigator>
				</view>
				<view class="withdraw-sub-btn">
					<button @tap="submit" form-type="submit" role="button" aria-disabled="false">提交申请</button>
				</view>
			</view>
			<view class="withdraw-foot-wrap">
				<text>
					温馨提示：
				</text>
				<text>
					1.提现金额须大于{{configInfo.cash_min_cash}}元，小于{{configInfo.cash_max_cash}}元
				</text>
				<text>
					2.提现收取{{configInfo.cash_service_ratio}}%的手续费，每笔最低{{configInfo.cash_min_service_money}}元手续费
				</text>
				<text>
					3.手续费在到账金额中扣除
				</text>
				<text>
					4.提现审核一般3 - 5个工作日到账
				</text>
			</view>
		</view>
	</view>
</template>

<script>
	const globalData=getApp().globalData//从app.vue获取用户信息
	import {getSurvey,getOauthList,postWithdrawal,getConfig} from "@/api/api";
	import Md from "md5";
	import common from "@/common/common.js";
	export default {
		data() {
			return {
				configInfo:"",//配置信息
				userInfo:"",//用户信息
				withdraw:"",//提现
				way:"",//方式
				pay_pwd:"",
				// poundage:0,//手续费
				params:{
					"bank_card": "",
					"bank_name": "微信",
					"money": "",
					"pay_pwd": "",
					"realname":"",
					"type": 0
				}
			};
		},
		onShow(){
			this.getSurvey()
			this.getOauthList()
			if(this.configInfo==""){
				this.getConfig()
				this.getUserInfo()
			}
			this.configInfo= globalData.configInfo;
			this.userInfo=globalData.userInfo;
			
		},
		computed: {
			/*计算手续费*/ 
			poundage(){
				var free= (this.params.money * this.configInfo.cash_service_ratio) / 100
				if(!this.configInfo.cash_service_ratio){
					return 0.00;
				}else{
					if(free<this.configInfo.cash_max_service_money){
						return this.filter(free);
					}else if(free>this.configInfo.cash_max_service_money){
						if(this.configInfo.cash_max_service_money>0){
							return this.filter(this.configInfo.cash_max_service_money)
						}else{
							return this.filter(free)
						}
					}
					return this.filter(free)
				}
				
			}
		},
		methods: {
			/*配置信息*/ 
			getConfig(){
				getConfig().then(res=>{
					if(res){
						// console.log(res)
						this.configInfo=res;
						getApp().globalData.configInfo=res;
					}
					
				})
			},
			/*用户信息*/
			getUserInfo(){
				getUserInfo().then(res=>{
					if(res){
						// console.log(res)
						if(res.head_pic.indexOf("public")==1){ //判断头像 是否有 域名
							let hostUrl=config.host;//路径前缀
							res.head_pic=hostUrl+res.head_pic;//路径前缀
						}
						this.userInfo=res;
						getApp().globalData.userInfo=res;
					}
				})
			},
			/*绑定三方平台列表*/ 
			getOauthList(){
				getOauthList().then(res=>{
					console.log(res)
					this.way=res;
				})
			},
			/*提示绑定微信*/ 
			bindWechat(){
				common.toast("none","请打开电脑端扫码绑定微信",3000)
			},
			/*分销概况*/ 
			getSurvey(){
				getSurvey().then(res=>{
					console.log(res)
					this.withdraw=res;
				})
			},
			/*全部提现*/
			allWithdraw(){
				this.params.money=this.withdraw.able_withdraw_money
			},
			/*设置密码*/ 
			userinfoEdit(e){
				if(this.userInfo.mobile){
					common.toast("none","请先设置手机号",2000);
					uni.navigateTo({
						url:`/pages/user/userinfo_edit/userinfo_edit?type=mobile`
					})
				}else{
					uni.navigateTo({
						url: e.currentTarget.dataset.url,
					})
				}
			},
			/*保留两位小数*/
			filter(e) {
				let num = parseFloat(e).toFixed(2)
				return num;
			},
			/*提交申请*/
			submit(){
				var wxchat;
				if(this.way){
					wxchat=this.way.filter(item=>{
						return item.oauth=="miniapp"
					})
					this.params.bank_card=wxchat.openid;
				}
				if(wxchat.openid==""||wxchat==""){
					return common.toast("none","请打开电脑端扫码绑定微信",2000);
				}
				if(this.userInfo.nickname){
					this.params.realname=this.userInfo.nickname;
				}else{
					if(this.params.realname==""||this.params.realname=="undefined"){
						return common.toast("none","请去设置您的昵称",2000)
					}
				}
				if(this.params.money==""){
					return common.toast("none","请输入金额",2000)
				}
				if(this.params.money<=0){
					return common.toast("none","请输入正确的金额",2000)
				}
				if(this.pay_pwd==""){
					return common.toast("none","请输入支付密码",2000)
				}
				this.params.pay_pwd=Md("TPSHOP"+this.pay_pwd)
				this.postWithdrawal(this.params)
			},
			postWithdrawal(params){
				postWithdrawal(params).then(res=>{
					if(res.status==200){
						common.toast("none",res.msg,3000)
						uni.navigateBack({
							delta:1
						})
					}else{
						common.toast("none",res.msg,3000)
					}
				})
			}
		},
	}
</script>

<style lang="scss">
	/* withdrawals.wxss */

	page {
		background-color: #f5f5f5;
	}

	.withdraw_container {
		width: 100%;
	}

	.withdraw-header-wrap {
		height: 180rpx;
		background-color: #ff594a;
		color: #fff;
		padding: 60rpx 30rpx;
	}

	.can_money_tit {
		font-size: 30rpx;
		line-height: 36rpx;
	}

	.can_money_tit text:first-child {
		display: inline-block;
		width: 36rpx;
		height: 36rpx;
		text-align: center;
		font-size: 24rpx;
		border: 1px solid #fff;
		border-radius: 50%;
		margin-right: 20rpx;
	}

	.can_money_con {
		margin-top: 66rpx;
		font-size: 24rpx;
	}

	.can_money_con text {
		font-size: 54rpx;
		margin-left: 20rpx;
	}

	.withdraw_style {
		padding: 30rpx 30rpx;
	}

	.withdraw_stna {
		font-size: 30rpx;
	}

	.withdraw_stcon {
		margin-top: 20rpx;
		line-height: 51rpx;
		overflow: hidden;
	}

	.withdraw_stcon image {
		width: 51rpx;
		height: 51rpx;
		float: left;
	}

	.withdraw_stcon .wh_user_account {
		font-size: 28rpx;
		float: left;
		margin-left: 20rpx;
	}

	.withdraw-cont-wrap {
		padding: 0 30rpx;
		border-top: 18rpx solid #f3f3f3;
		font-size: 30rpx;
	}

	.withdraw-cont-wrap .withdraw-cont-p1 {
		padding: 40rpx 0 20rpx;
		height: 30rpx;
		color: #4c4c4c;
		font-size: 26rpx;
	}

	.withdraw-cont-wrap .withdraw-cont-p1 text {
		margin-left: 10rpx;
	}

	.withdraw-money {
		overflow: hidden;
		padding-top: 20rpx;
	}

	.withdraw-money text {
		float: left;
	}

	.withdraw-money input {
		width: 94%;
		border-bottom: 1px solid #f3f3f3;
		float: right;
		font-size: 36rpx;
	}

	.withdraw-allmoney {
		height: 90rpx;
		line-height: 90rpx;
		font-size: 30rpx;
	}

	.withdraw-allmoney text {
		float: left;
	}

	.withdraw-allmoney .wh_allmony {
		float: right;
		width: 140rpx;
		height: 90rpx;
		line-height: 90rpx;
		color: #ff594a;
		background-color: transparent;
	}

	button::after {
		border: none;
	}

	.withdraw-cont-wrap .withdraw-cont-p2 {
		padding-top: 20rpx;
		height: 90rpx;
		line-height: 90rpx;
	}

	.withdraw-cont-p2 {
		border-bottom: 1px solid #f3f3f3;
	}

	.withdraw-cont-p2 text {
		float: left;
	}

	.withdraw-cont-p2 input {
		float: left;
		height: 90rpx;
		line-height: 90rpx;
		margin-left: 10rpx;
	}

	.wh_setpsd {
		width: 100%;
		overflow: hidden;
	}

	.wh_setpsd navigator {
		float: right;
		height: 72rpx;
		line-height: 72rpx;
		color: #ff594a;
		background-color: transparent;
	}

	.withdraw-sub-btn {
		margin: 75rpx 0;
	}

	.withdraw-sub-btn button {
		width: 100%;
		height: 88rpx;
		line-height: 88rpx;
		color: #ffffff;
		background-color: #e73223;
		font-size: 36rpx;
		border-radius: 10rpx;
	}

	.withdraw-foot-wrap {
		padding: 0 30rpx;
		font-size: 24rpx;
		color: #666;
		margin-bottom: 60rpx;
	}

	.withdraw-foot-wrap text {
		display: block;
		line-height: 36rpx;
	}
</style>
